package resources.calendar;

import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import model.calendar.Calendar;
import dao.CalendarDAO;
import dao.Linker;

public class CalendarRes 
{
	@Context
	UriInfo uriInfo;
	
	@Context
	Request request;
	
	String calendarId;
	
	public CalendarRes(UriInfo uriInfo, Request request, String calendarId) 
	{
		this.uriInfo = uriInfo;
		this.request = request;
		this.calendarId = calendarId;
	}
	
	@GET
	@Produces(MediaType.TEXT_XML)
	public Calendar getDataBrowser() 
	{
		Linker.sort();
		
		Calendar calendar = CalendarDAO.getCalendarsCP().get(calendarId);
		
		if(calendar == null)
			throw new RuntimeException("Get: Calendar " + calendarId +  " not found");
		return calendar;
	}
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public Calendar getDataBrowserJSON() 
	{
		return getDataBrowser(); 
	}
	
	@GET
	@Produces(MediaType.APPLICATION_XHTML_XML)
	public Calendar getDataBrowserXHTML() 
	{
		return getDataBrowser(); 
	}
	
	@GET
	@Produces(MediaType.APPLICATION_XML)
	public Calendar getDataBrowserXML() 
	{
		return getDataBrowser(); 
	}
}